package com.yeskery.nut.web.demo.controller;

import com.yeskery.nut.annotation.bean.Autowired;
import com.yeskery.nut.annotation.web.Controller;
import com.yeskery.nut.annotation.web.GetMapping;
import com.yeskery.nut.annotation.web.ResponseBody;
import com.yeskery.nut.core.Model;
import com.yeskery.nut.core.Version;
import com.yeskery.nut.web.demo.common.R;
import com.yeskery.nut.web.demo.feign.HttpFeignClient;

/**
 * 首页controller
 * @author YESKERY
 * 2023/11/6
 */
@Controller
public class IndexController {

    @Autowired
    private HttpFeignClient httpFeignClient;

    @GetMapping({"/", "/index"})
    public String index(Model model) {
        model.addAttribute("nutVersion", Version.VERSION);
        return "index";
    }

    @GetMapping("/upload")
    public String upload() {
        return "upload";
    }

    @GetMapping("/version")
    @ResponseBody
    public R<String> version() {
        return R.ok(Version.VERSION);
    }

    @GetMapping("/feign/version")
    @ResponseBody
    public R<String> feignVersion() {
        R<String> r = httpFeignClient.version();
        r.setData("feign request: " + r.getData());
        return r;
    }
}
